﻿@model PH.Model.Schools.ClassModel

<div class="GeneralEdit" id="fmClass">
    <ul>

         <li>
            <label for="txtClassIndex">班级序号：</label>
            <input type="number" class="k-textbox" id="txtClassIndex" name="classIndex" value="@Model.CIndex" required pattern="^\d{1,2}$" validationMessage="请输入班级编号(1-99的数字)" />
            <span class="k-invalid-msg" data-for="classIndex"></span>
        </li>
        @if (PH.Web.Global.WebContext.CurrentSchool.SchType == 4)
        {
            <li>
                <label for="txtClassName">班级名称：</label>
                <input type="text" class="k-textbox" id="txtClassName" name="className" value="@Model.ClassName" required validationMessage="请输入班级名称" />
                <span class="k-invalid-msg" data-for="className"></span>
            </li>
        }
        <li>
            <label for="ddlGrade">年级：</label>
            <select id="ddlGrade"></select>
        </li>
        <li>
            <label for="txtAdvisor">班主任：</label>
            <input type="text" class="k-textbox" id="txtAdvisor" name="advisor" value="@Model.Advisor" maxlength="10" />
            <span class="k-invalid-msg" data-for="advisor"></span>
        </li>
        <li class="editButtons">
            <button id="btnSaveClass" class="k-button"><span class="k-icon k-i-tick"></span><span>确认提交</span></button>
            &nbsp;&nbsp;
            <button class="k-button" onclick="CancelGeneralEdit();"><span class="k-icon k-i-cancel"></span><span>&nbsp;返&nbsp;回</span></button>
        </li>
    </ul>
</div>

<script class="init">
    $("#ddlGrade").kendoDropDownList({
        dataTextField: "GradeName",
        dataValueField: "Code",
        dataSource: Whale.dataSource({
            url: "/School/Config/GetGrades",
            getParameters: function () {
                return {
                    schType: "@PH.Web.Global.WebContext.CurrentSchool.SchType"
                }
            }
        }),
        dataBound: function (e) {
            var sel = $("#ddlGrade").data("kendoDropDownList");
            sel.select(function (dataItem) {
                return dataItem.Code == "@Model.GradeCode";
            });
        }
    });
</script>

<script class="save_class">
    $(function () {
        var validator = $("#fmClass").kendoValidator().data("kendoValidator");
        $("#btnSaveClass").click(function (e) {
            if (validator.validate()) {
                var values = {
                    guid: "@Model.Guid",
                    schoolGuid: "@PH.Web.Global.WebContext.CurrentSchool.Guid",
                    className: $("#txtClassName").val(),
                    gradeCode: $("#ddlGrade").data("kendoDropDownList").value(),
                    advisor: $("#txtAdvisor").val(),
                    cindex: $("#txtClassIndex").val(),

                };

                Whale.Remote.Operation({
                    url: "/School/Class/SaveClass",
                    parameters: values,
                    success: function (result) {
                        wndGeneralEdit.close();
                        if ($("#grid_class").length > 0)
                            $("#grid_class").data("kendoGrid").dataSource.read();
                    },
                    error: function (msg) {
                        wndGeneralInformation.content(msg).open();
                    }
                });
            }
            return false;
        });
    });
</script>
